home *** CD-ROM | disk | FTP | other *** search
/ Symantec Visual Cafe for Java 2.5 / symantec-visual-cafe-2.5-database-dev-edition.iso / Visual Cafe Pro v1.0 / TUTORIAL.BIN / Bit.class (.txt) < prev    next >
Encoding:
Java Class File  |  1997-01-30  |  4.0 KB  |  134 lines

  1. package symantec.itools.db.net;
  2.  
  3. import java.io.DataOutputStream;
  4. import java.io.IOException;
  5. import symjava.lang.Bignum;
  6. import symjava.sql.SQLException;
  7.  
  8. class Bit extends NumberField {
  9.    boolean _bVal;
  10.  
  11.    int getType() {
  12.       return 87;
  13.    }
  14.  
  15.    void readData(ServerObject data) throws SQLException, IOException, ErrorException {
  16.       this._bVal = ((NetData)data).getBool();
  17.    }
  18.  
  19.    void writeData(DataOutputStream os) throws IOException {
  20.       NetData data = new NetData(this._bVal);
  21.       data.write(os);
  22.    }
  23.  
  24.    public String getString() throws SQLException {
  25.       return ((Field)this).isNull() ? null : String.valueOf(this._bVal);
  26.    }
  27.  
  28.    public boolean getBoolean() throws SQLException {
  29.       return ((Field)this).isNull() ? false : this._bVal;
  30.    }
  31.  
  32.    public byte getByte() throws SQLException {
  33.       if (((Field)this).isNull()) {
  34.          return 0;
  35.       } else {
  36.          return (byte)(this._bVal ? 1 : 0);
  37.       }
  38.    }
  39.  
  40.    public short getShort() throws SQLException {
  41.       if (((Field)this).isNull()) {
  42.          return 0;
  43.       } else {
  44.          return (short)(this._bVal ? 1 : 0);
  45.       }
  46.    }
  47.  
  48.    public int getInt() throws SQLException {
  49.       if (((Field)this).isNull()) {
  50.          return 0;
  51.       } else {
  52.          return this._bVal ? 1 : 0;
  53.       }
  54.    }
  55.  
  56.    public long getLong() throws SQLException {
  57.       return ((Field)this).isNull() ? 0L : (long)(this._bVal ? 1 : 0);
  58.    }
  59.  
  60.    public float getFloat() throws SQLException {
  61.       return ((Field)this).isNull() ? 0.0F : (float)(this._bVal ? 1 : 0);
  62.    }
  63.  
  64.    public double getDouble() throws SQLException {
  65.       if (((Field)this).isNull()) {
  66.          return (double)0.0F;
  67.       } else {
  68.          return this._bVal ? (double)1.0F : (double)0.0F;
  69.       }
  70.    }
  71.  
  72.    public Bignum getBignum(int scale) throws SQLException {
  73.       return ((Field)this).isNull() ? null : new Bignum(this._bVal ? 1 : 0, scale);
  74.    }
  75.  
  76.    public void setBoolean(boolean x) throws SQLException {
  77.       this._bVal = x;
  78.       super._null = false;
  79.    }
  80.  
  81.    public void setByte(byte x) throws SQLException {
  82.       this._bVal = x != 0;
  83.       super._null = false;
  84.    }
  85.  
  86.    public void setShort(short x) throws SQLException {
  87.       this._bVal = x != 0;
  88.       super._null = false;
  89.    }
  90.  
  91.    public void setInt(int x) throws SQLException {
  92.       this._bVal = x != 0;
  93.       super._null = false;
  94.    }
  95.  
  96.    public void setLong(long x) throws SQLException {
  97.       this._bVal = x != 0L;
  98.       super._null = false;
  99.    }
  100.  
  101.    public void setFloat(float x) throws SQLException {
  102.       this._bVal = x != 0.0F;
  103.       super._null = false;
  104.    }
  105.  
  106.    public void setDouble(double x) throws SQLException {
  107.       this._bVal = x != (double)0.0F;
  108.       super._null = false;
  109.    }
  110.  
  111.    public void setBignum(Bignum x) throws SQLException {
  112.       this._bVal = x.intValue() != 0;
  113.       super._null = false;
  114.    }
  115.  
  116.    public void setString(String x) throws SQLException {
  117.       Integer i = new Integer(x);
  118.       this._bVal = i != 0;
  119.       super._null = false;
  120.    }
  121.  
  122.    public int getSQLType() {
  123.       return -7;
  124.    }
  125.  
  126.    public Object getObject() throws SQLException {
  127.       return new Boolean(this._bVal);
  128.    }
  129.  
  130.    public void setObject(Object obj) throws SQLException {
  131.       this.setBoolean((Boolean)obj);
  132.    }
  133. }
  134.